package com.xh.bussiness.tiku.bean.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.xh.bussiness.practice.bean.dto.PracticeStudentResultDTO;
import com.xh.bussiness.practice.model.PracticeStudentResult;
import com.xh.bussiness.tiku.model.BookChapter;
import com.xh.bussiness.tiku.model.Knowledge;
import com.xh.bussiness.tiku.model.QuestionSource;
import com.xh.core.bean.BaseDto;
import com.xh.core.convert.JSONConverter;
import com.xh.core.util.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/*
 * @Author daiwei
 * @Description
 * @Date 2019/1/15 10:42
 **/
@Data
@ApiModel
public class QuestionDto extends BaseDto  implements Serializable {
    /**
     * id
     */
    @ApiModelProperty("id")
    private String id;

    /**
     * 分数
     */
    @ApiModelProperty("分数")
    private Integer score;
    /**
     * 题干
     */
    @ApiModelProperty("题干")
    private String title;

    /**
     * 题干
     */
    @ApiModelProperty("题号")
    private String questionNo;


    /**
     * 题目来源，1 自建，2 菁优网
     */
    @ApiModelProperty("题目来源，1 自建，2 菁优网")
    private Integer sourceFrom;
    /**
     * 当前版本
     */
    @ApiModelProperty("当前版本")
    private Integer currentVersion;

    /**
     * 学科id
     */
    @ApiModelProperty("科目ID")
    private String subjectId;

    private Integer xkwSubjectId;
    
    /**
     *学科
     */
    @ApiModelProperty("科目")
    private String subjectName;

    /**
     * 知识点id
     */
    @ApiModelProperty("知识点ID集合")
    private List<String> knowledgePoints;

    @ApiModelProperty("章节ID集合")
    private List<String> chaptersIds;
    
    /**
     * 知识点
     */
    @ApiModelProperty("知识点集合")
    private List<Knowledge> knowledges;

    @ApiModelProperty("章节集合")
    private List<BookChapter> bookChapters;
    /**
     * 题型
     */
    @ApiModelProperty("题型")
    private Integer type;

    @ApiModelProperty("试题类型名称")
    private String questionTypeName;

    /**
     * 基本试题类型（
     * 1：单选题，2：多选题，3：判断题，
     * 5：解答题，6：排序题，7：连线题，
     * 8：匹配题，9:阅读理解,10:完形填空,11:综合题
     * 12：其他
     * ）
     */
    @ApiModelProperty("基本试题类型（ 1：单选题，2：多选题，3：判断题， 5：解答题，6：排序题，7：连线题，8：匹配题，9:阅读理解,10:完形填空,11:综合题,12:其他）")
    private Integer basicQuestionType;

    @ApiModelProperty("基本试题类型（ 1：单选题，2：多选题，3：判断题， 5：解答题，6：排序题，7：连线题，8：匹配题，9:阅读理解,10:完形填空,11:综合题,12:其他）")
    private String basicQuestionTypeName;
    /**
     * 难度
     */
    @ApiModelProperty("难度")
    private Integer difficult;
    /**
     * 正确答案
     */
    @ApiModelProperty("正确答案")
    @JsonDeserialize(using = JSONConverter.class)
    private JSON rightAnswer;

    private String rightAnswerContent;
    /**
     * 使用次数
     */
    @ApiModelProperty("使用次数")
    private Integer useCount;


    @ApiModelProperty("题类")
    private String category;
    /**
     * 作答次数
     */
    @ApiModelProperty("作答次数")
    private Integer answerCount;
    /**
     * 作答正确次数
     */
    @ApiModelProperty("作答正确次数")
    private Integer answerRightCount;

    /**
     * 解析
     */
    @ApiModelProperty("解析")
    private String analysis;

    /**
     * 付费解析
     */
    @ApiModelProperty("付费解析")
    private String analysisPay;

    /**
     * 考点分析
     */
    @ApiModelProperty("考点分析")
    private String examPoint;

    /**
     * 视频解析
     */
    @ApiModelProperty("视频解析")
    private String analysisVideo;

    private Integer startRow;

    private Integer endRow;

    private Integer status;

    @ApiModelProperty("试题数据是否正确")
    private Boolean dataRight;

    @ApiModelProperty("试题数据错误原因")
    private String dataErrorMsg;

    @ApiModelProperty("试题选项")
    @JsonDeserialize(using = JSONConverter.class)
    private JSON option;

    @ApiModelProperty
    private String optionContent;

    @ApiModelProperty("试题来源")
    private String source;
    
    @ApiModelProperty("年份")
    private String year;

    @ApiModelProperty("序号")
    private Integer orderNo;
    
    @ApiModelProperty("创建人")
    private String creator;
    
    private Integer contentType;
    
    private String refId;
    
    private String imgPath;
    
    @JsonIgnore
    List<QuestionOptionDto> options;

    @ApiModelProperty("子试题")
    List<QuestionDto> childs;

    @ApiModelProperty("是否已收藏")
    private Boolean isCollect;

    @ApiModelProperty("错误信息")
    private String failReason;

    @ApiModelProperty("重复信息")
    private List<Map> RepetitionRateList;

    private List<Map<String,String>> repeatInfos;
    /**
     * 每行排列几个选项
     */
    private Integer optionNum;

    /**
     * 年级id
     */
    @ApiModelProperty(value = "年级",notes ="年级" ,dataType = "Integer", required = true)
    private String gradeId;

    @ApiModelProperty(value = "试题来源")
    private List<QuestionSource> questionSources;

    @ApiModelProperty(value = "试题章节知识点关系")
    private List<QuestionChapterKnowledgeDTO> chapterKnowles;

    /**
     * 相似度
     */
    @ApiModelProperty(value = "相似度")
    private String similarDegree;

    /**
     * 学生作答结果
     */
    @ApiModelProperty(value = "学生作答结果")
    private PracticeStudentResultDTO practiceStudentResultDTO;

    /**
     * 省id
     */
    @ApiModelProperty(value = "省id",notes ="省id" ,dataType = "String")
    private String proviceId;

    /**
     * 市id
     */
    @ApiModelProperty(value = "市id",notes ="市id" ,dataType = "String")
    private String cityId;

    @ApiModelProperty("排列方式：1:每行一个选项；2:每行两个选项 3:每行4个选项")
    private Integer optionArrangements;

    /**
     * 视频
     **/
    private String videoPath;

    /**
     * 无声视频
     **/
    private String silentVideoPath;

    /**
     * 音频
     **/
    private String voicePath;

    /**
     * 标签
     **/
    @ApiModelProperty("标签")
    private String labels;

    public String getOptionStr() {
        if (this.option == null) {
            return "";
        }
        String optionStr = "";
        JSONArray array = JSON.parseArray(this.option.toJSONString());
        if(this.basicQuestionType!=null && this.basicQuestionType==7){//连线题
            for (int i = 0; i < array.size(); i++) {
                JSONArray optArray = array.getJSONArray(i);
                for(int j = 0;j<optArray.size();j++){
                    JSONObject json = optArray.getJSONObject(j);
                    optionStr += json.getString("content");
                }
            }
        }else {
            for (int i = 0; i < array.size(); i++) {
                JSONObject json = array.getJSONObject(i);
                optionStr += json.getString("content");
            }
        }

        return optionStr;
    }


}
